package com.felix.ocoupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author hsufelix
 * @email hsufelix@yeah.net
 * @Date 2020/11/11
 * <h1>优惠券分类</h1>
 */
@Getter
@AllArgsConstructor
public enum OcouponCategory {
    MANJIAN("满减券", "000001"),
    ZHEKOU("折扣券", "000002"),
    LIJIAN("立减券", "000003");

    private String description;

    private String code;

    public static OcouponCategory of (String code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(
                        code + "not exists"
                ));
    }

}
